﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace sieuthi
{
    public partial class mathang : Form
    {
        private SqlDataAdapter da = new SqlDataAdapter();
        private SqlConnection conn = new SqlConnection(Threelayer.VO.core.connectionsring.ToString());
        private SqlCommand cmd = new SqlCommand();
        private DataTable dt = new DataTable("mathang");
        Threelayer.VO.mathang mh_vo;
        Threelayer.BUS.mathangBUS mh_bus;
        public mathang()
        {
            InitializeComponent();
        }

        private void mathang_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'sieuthiDataSet2.mathangVIEW' table. You can move, or remove it, as needed.
            this.mathangVIEWTableAdapter3.Fill(this.sieuthiDataSet2.mathangVIEW);
            // TODO: This line of code loads data into the 'sieuthiDataSet2.gianhang' table. You can move, or remove it, as needed.
            this.gianhangTableAdapter.Fill(this.sieuthiDataSet2.gianhang);
            // TODO: This line of code loads data into the 'sieuthiDataSet2.mathang' table. You can move, or remove it, as needed.
            this.mathangTableAdapter1.Fill(this.sieuthiDataSet2.mathang);
            mhbinding();
        }
        private void mhbinding()
        {
            box_mamh.DataBindings.Clear();
            box_mamh.DataBindings.Add("text", dataGridkhachhang.DataSource, "mamh");
            box_dvt.DataBindings.Clear();
            box_dvt.DataBindings.Add("text", dataGridkhachhang.DataSource, "dvt");
            box_tenmh.DataBindings.Clear();
            box_tenmh.DataBindings.Add("text", dataGridkhachhang.DataSource, "tenmh");
            box_magh.DataBindings.Clear();
            box_magh.DataBindings.Add("text", dataGridkhachhang.DataSource, "magh");
        }
        private void data_mathang()
        {
            mh_vo = new Threelayer.VO.mathang();
            mh_vo.DVT = box_dvt.Text;
            mh_vo.MaGH = box_magh.Text;
            mh_vo.MaMH = box_mamh.Text;
            mh_vo.TenMH = box_tenmh.Text;
        }

        private void bt_khachhang_them_Click(object sender, EventArgs e)
        {
            data_mathang();
            mh_bus = new Threelayer.BUS.mathangBUS();
            mh_bus.mathang_them(mh_vo);
            mathang_Load(sender,e);
        }

        private void bt_khachhang_sua_Click(object sender, EventArgs e)
        {
            data_mathang();
            mh_bus = new Threelayer.BUS.mathangBUS();
            mh_bus.mathang_sua(mh_vo);
            mathang_Load(sender, e);
        }

        private void bt_khachhang_xoa_Click(object sender, EventArgs e)
        {
            data_mathang();
            mh_bus = new Threelayer.BUS.mathangBUS();
            mh_bus.mathang_xoa(box_mathang_timkiem.Text);
            mathang_Load(sender, e);
        }

        private void bt_khachhang_timkiem_Click(object sender, EventArgs e)
        {
            dt.Clear();
            cmd.Dispose();
            cmd.Parameters.Clear();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.StoredProcedure;
            conn.Open();
            cmd.CommandText = "mathang_timkiem";
            cmd.Parameters.Add("@mamh", SqlDbType.NVarChar, 200).Value = box_mathang_timkiem.Text;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            cmd.ExecuteNonQuery();
            da.Fill(dt);
            dataGridkhachhang.DataSource = dt;
            conn.Close();
        }

    }
}
